#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int lengthOfLastWord(string s) {
        int tail = s.size();
        while (tail >= 0)
        {
            if (isalpha(s[tail]))
            {
                break;
            }
            tail--;
        }
        int head = tail;
        int count = 0;
        while (head >= 0)
        {
            if (!isalpha(s[head]))
            {
                break;
            }
            head--;
            count++;
        }

        return count;
    }
};